<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button v-if="!disabledButton" @click="handleAdd" type="primary" icon="plus" :disabled="isDisabledAuth('erpHrApplyEducation:add')">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="false"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="status" slot-scope="status">
           <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
        <template v-if="!disabledButton">
                <a-button
                        class="ruleButton"
                        :ghost="true"
                        type="primary"
                        icon="edit"
                        @click="handleEdit(record)"
                        :disabled="isDisabledAuth('erpHrApplyEducation:edit')"
                />
                <a-divider type="vertical"/>
                <a-popconfirm title="确定删除吗?" @confirm="() => listDelete(record.id)">
                    <a-button
                            class="ruleButton"
                            :ghost="true"
                            type="primary"
                            icon="delete"
                            :disabled="isDisabledAuth('erpHrApplyEducation:delete')"/>
                </a-popconfirm>
        </template>
        </span>

      </a-table>
    </div>

    <erp-hr-apply-education-modal ref="modalForm" @ok="handleOk"></erp-hr-apply-education-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ErpHrApplyEducationModal from './modules/ErpHrApplyEducationModal'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'

  export default {
    name: 'ErpHrApplyEducationList',
    mixins:[JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpHrApplyEducationModal,
    },
    props:{
      disabledButton:{
        type: Boolean,
        default:false,
      },
      newData: {
        type: Array,
      }
    },
    data () {
      return {
        description: '应聘登记表-教育经历信息管理页面',
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'开始时间',
            align:"center",
            dataIndex: 'beginDate',
          },
          {
            title:'结束时间',
            align:"center",
            dataIndex: 'endDate',
          },
          // {
          //   title:'教育单位',
          //   align:"center",
          //   dataIndex: 'institution',
          // },
          {
            title:'学校名称',
            align:"center",
            dataIndex: 'graduatedFrom',
          },
          {
            title:'专业',
            align:"center",
            dataIndex: 'major',
          },
          {
            title:'获奖情况',
            align:"center",
            dataIndex: 'prizeRecord',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
            }
          }
        ],
        url: {
          list: "/api/erp/hr/apply/erpHrApplyEducation/list",
          list0: "/api/erp/hr/apply/erpHrApplyEducation/list?applyId=",
          delete: "/api/erp/hr/apply/erpHrApplyEducation/delete",
          deleteBatch: "/api/erp/hr/apply/erpHrApplyEducation/deleteBatch",
          exportXlsUrl: "/api/erp/hr/apply/erpHrApplyEducation/exportXls",
          exportXlsUrl0: "/api/erp/hr/apply/erpHrApplyEducation/exportXls?applyId=",
          importExcelUrl: "api/erp/hr/apply/erpHrApplyEducation/importExcel",
          importExcelUrl0: "api/erp/hr/apply/erpHrApplyEducation/importExcel?foreignKey=applyId&mainId=",
        },
        dictOptions:{},
        superFieldList:[],
        disableMixinCreated:true,
        colsettings:'ErpHrApplyEducation:colsettings',
      }
    },
    watch: {
      $route(to, from) {
      //  this.url.list = this.url.list0 + this.$route.params.id;
        this.url.exportXlsUrl = this.url.exportXlsUrl0 + this.$route.params.id;
        this.url.importExcelUrl = this.url.importExcelUrl0 + this.$route.params.id;
      //  this.loadData();
      },
      newData(newValue){
        this.dataSource = Object.assign([],newValue)
      }
    },
    created() {
      this.getSuperFieldList();
    //  this.url.list = this.url.list0 + this.$route.params.id;
      this.url.exportXlsUrl = this.url.exportXlsUrl0 + this.$route.params.id;
      this.url.importExcelUrl = this.url.importExcelUrl0 + this.$route.params.id;
    //  this.loadData();
      this.initColumns();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      listDelete(id){
        this.dataSource.forEach((val,index) => {
          if(val.id === id){
            this.dataSource.splice(index,1)
          }
        })
        this.$emit('delete',this.dataSource)
      },
      handleOk(val){
        console.log(val);
        if(val.id){
          let index = this.dataSource.findIndex(item => item.id === val.id)
          this.dataSource.splice(index,1,val)
        } else {
          this.dataSource.push({id: parseInt((Math.random()*1000000000)).toString(),...val})
        }
        this.$emit('ok',this.dataSource)
      },
      initDictConfig(){
      },
      handleAdd: function() {
        this.$refs.modalForm.edit({
            'applyId':this.$route.params.id
        })
        this.$refs.modalForm.title = '新增'
        this.$refs.modalForm.disableSubmit = false
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'date',value:'beginDate',text:'开始时间'})
        fieldList.push({type:'date',value:'endDate',text:'结束时间'})
        fieldList.push({type:'string',value:'institution',text:'教育单位',dictCode:''})
        fieldList.push({type:'string',value:'major',text:'专业',dictCode:''})
        fieldList.push({type:'string',value:'graduatedFrom',text:'学校名称',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
